# -*- coding: utf-8 -*-
"""
Created on Wed Nov 02 17:11:21 2016

@author: Divyashri Sreedharan Nair
"""

from androguard.core.bytecodes import dvm, apk 
from androguard.core.analysis import analysis, ganalysis
from androguard.decompiler import decompiler

import os
cwd = os.getcwd()

def AnalyzeDex(f) :
    
    d = dvm.DalvikVMFormat(f.get_dex())
    
    # VMAnalysis
    dx = analysis.VMAnalysis( d )
    #dx = uVMAnalysis( d )
    
    d.set_vmanalysis(dx)
    	
    return d, dx

def grab_filename(apk) :
	"""
		@param apk : an APK instance
		@rtype : the APK's filename
	"""
	return apk.filename.split('/')[-1]

def grab_permission_classes(vm) :
    """
		@param vm : a dex file
		@rtype : the APK's filename
    """
    analysis.show_Permissions(vm)
    
print("=====================================")
TEST = "C:/Users/admin/Desktop/samples/samples/ADRD/ffe62967b75aab56710110b26baa69acd47a81dd.apk"

a = apk.APK(TEST)
d,dx =  AnalyzeDex(a)

print "\nAPK Filename: \n"+ str(grab_filename(a))
print "\nPermission Activities: \n"+ str(grab_permission_classes(dx))
print("=====================================")